package com.iflytek.hive.need3;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class AmountDiffMapper extends Mapper<LongWritable, Text, Text, Text> {
    private final Text keyOut1 = new Text();
    private final Text keyOut2 = new Text();
    private final Text valueOut1 = new Text();
    private final Text valueOut2 = new Text();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 将行文本数据切分
        String[] fields = value.toString().split(",");
        keyOut1.set(fields[0]);
        valueOut1.set(fields[0]+":"+fields[1]);
        int afteryear = Integer.valueOf(fields[0]) + 1;
        String afteryear1 = String.valueOf(afteryear);
        keyOut2.set(afteryear1);
        valueOut2.set(fields[0]+":"+fields[1]);
        System.out.println();
        context.write(keyOut2,valueOut2);
        context.write(keyOut1,valueOut1);
    }

}
